package xiangmu.schoolpaper.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xiangmu.schoolpaper.mapper.AdminDataListMapper;
import xiangmu.schoolpaper.pojo.VO.*;
import xiangmu.schoolpaper.service.AdminDataListService;

import java.util.List;

@Service

public class AdminDataListServiceImpl implements AdminDataListService {
    @Autowired
    private AdminDataListMapper adminDataListMapper;

    @Override
    public List<Integer> graduationYear(Integer facultyId) {
        return adminDataListMapper.graduationYear(facultyId);
    }

    @Override
    public List<SystemNameAndAccount> nameAndId(Integer facultyId) {
        return adminDataListMapper.nameAndId(facultyId);
    }

    @Override
    public IPage<SystemSplitStudentInfo> getAllStudentPaper(
            Integer currentPage,
            Integer pageSize,
            Integer facultyId,
            Integer graduationYear,
            String studentAccount,
            String paperTitle
    ) {
        Page<SystemSplitStudentInfo> page = new Page<>(currentPage, pageSize);
        return adminDataListMapper.getAllStudentPaper(page, facultyId, graduationYear, studentAccount, paperTitle);
    }

    @Override
    public IPage<ExtractContentVO> extractContent(
            Integer currentPage,
            Integer pageSize,
            Integer facultyId,
            Integer graduationYear,
            String studentAccount,
            String paperTitle
    ) {
        Page<ExtractContentVO> page = new Page<>(currentPage, pageSize);
        return adminDataListMapper.extractContent(page, facultyId, graduationYear, studentAccount, paperTitle);
    }

    @Override
    public IPage<SystemOneScoreVO> allPaperScore(
            Integer currentPage,
            Integer pageSize,
            Integer facultyId,
            Integer graduationYear,
            String studentAccount,
            String paperTitle
    ) {
        Page<SystemOneScoreVO> page = new Page<>(currentPage, pageSize);
        return adminDataListMapper.allPaperScore(page, facultyId, graduationYear, studentAccount, paperTitle);
    }

    @Override
    public SystemAllScoreAndSuggestByStudentAccountVO getByStudentAccount(String studentAccount) {
        // 0. 根据学生学号获取到学生id
        Integer studentId = adminDataListMapper.getStudentIdByStudentAccount(studentAccount);

        // 1. 获取论文主信息
        SystemAllScoreAndSuggestByStudentAccountVO vo = adminDataListMapper.getPaperInfoByStudentId(studentId);
        if (vo == null) {
            return null;
        }

        // 2. 根据 paperId 获取 factor 列表
        List<SystemOneFactorInfoVO> factors = adminDataListMapper.getFactorsByPaperId(vo.getPaperId());

        // 3. 组装
        vo.setFactors(factors);

        return vo;
    }
}
